<!--学生考试首页-->
<template>
  <div id="student">
    <el-row class="padding-50">
      <el-col :span="24">
        <ul class="list">
          <li class="logo"><span>Exam-Online</span></li>
          <li><a href="javascript:void(0);" @click="toExam()">我的试卷  </a></li>
          <li><a href="javascript:void(0);" @click="toScore()">我的成绩</a></li>
          <li
            class="right"
            @mouseenter="flag = !flag"
            @mouseleave="flag = !flag"
          >
            <span>{{studentInfo.studentname }} </span>
            <div class="msg" v-if="flag">
              <p @click="manage()">管理中心</p>
              <p class="exit" @click="logoutHandle()">退出</p>
            </div>
          </li>
        </ul>
      </el-col>
    </el-row>
    <!--路由区域-->
    <div class="student">
      <router-view></router-view>
    </div>
  </div>
</template>


<script>
import store from "@/store";
export default {
  store,
  data() {
    return {
      loading: true,
      flag: false,
      user: {},
      studentInfo:{},
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    logoutHandle() {
      this.$confirm(`确定进行[退出]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl("/sys/logout"),
            method: "post",
            // data: this.$http.adornData(),
          }).then(({ data }) => {
            if (data.code === 0) {
              // clearLoginInfo();
              this.$router.push({ name: "login" });
            }
          });
        })
        .catch(() => {});
    },

    //跳转到修改密码页面
    manage() {
      this.$router.replace({ name: "manager" });
    },

    //获取用户信息
    getUserInfo() {
      this.$http({
        url: this.$http.adornUrl("/sys/user/info"),
        method: "get",
        // params: this.$http.adornParams(),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.user = data.user;

          this.$store.commit('updateId',this.user.userId);
           this.$store.commit('updateName',this.user.username);
          this.$http({
            url: this.$http.adornUrl(`/exam/student/info/${this.user.userId}`),
            method: "get",
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.studentInfo = data.student;
              this.$store.commit('student/updateStudentId', this.studentInfo.studentid)
              this.$store.commit('student/updateStudentName',this.studentInfo.studentname);
            }
          });

        }
      });
    },

    //跳转考试模式
    toExam() {
      this.$router.replace({ name: "myExam" });
    },
    //跳转成绩页面
    toScore() {
      this.$router.replace({ name: "scoreTable", query: { studentid: this.studentInfo.studentid } });
    },
  },
};
</script>



<style scoped>
.right .icon {
  margin-right: 6px;
}
#student .padding-50 {
  margin: 0 auto;
  padding: 0 50px;
  box-shadow: 0 0 10px 4px rgba(1, 149, 255, 0.1);
  background-color: #fff;
}
.list a {
  text-decoration: none;
  color: #334046;
}
li {
  list-style: none;
  height: 60px;
  line-height: 60px;
}
#student .list {
  display: flex;
}
#student .list li {
  padding: 0 20px;
  cursor: pointer;
}
#student .list li:hover {
  background-color: #0195ff;
  transition: all 2s ease;
}
#student .list li:hover a {
  color: #fff;
}
#student .list .right {
  margin-left: auto;
  position: relative;
}
#student .list li.right :hover a {
  color: #000;
}
#student .list .logo {
  display: flex;
  font-weight: bold;
  color: #2f6c9f;
}
#student .list .logo i {
  font-size: 50px;
}
.right .msg {
  text-align: center;
  position: absolute;
  top: 60px;
  left: 0px;
  display: flex;
  flex-direction: column;
  border-radius: 2px;
  border-bottom: 3px solid #0195ff;
  background-color: #fff;
}
.right .msg p {
  height: 40px;
  line-height: 40px;
  width: 105px;
}
.right .msg p:hover {
  background-color: #0195ff;
}
</style>
